//
//  ViewController.m
//  AnimationDemo
//
//  Created by Jiaozl 2018 on 2018/9/11.
//  Copyright © 2018年 Jiaozl. All rights reserved.
//

#import "ViewController.h"
#import "ZLTableItem.h"

@interface ViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;   ///<  列表

@property (nonatomic, strong) NSMutableArray *datas;   ///<  数据源

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:self.tableView];
    
    [self.datas addObject:ZLTableItem.tableItem(@"CATransition专场动画", @"ZLTransitionViewController", ZLAnimationTypeUnknow)];
    [self.datas addObject:ZLTableItem.tableItem(@"转场动画---视图控制器切换", @"TransitionFromViewController", ZLAnimationTypeUnknow)];
    [self.datas addObject:ZLTableItem.tableItem(@"粒子动画", @"EmitterAnimationViewController", ZLAnimationTypeUnknow)];
    

    [self.datas addObject:ZLTableItem.tableItem(@"水纹动画", @"AnimationViewController", ZLAnimationTypeWave)];
    [self.datas addObject:ZLTableItem.tableItem(@"弹性动画", @"AnimationViewController", ZLAnimationTypeSpringAnimation)];
    [self.datas addObject:ZLTableItem.tableItem(@"抛物线", @"AnimationViewController", ZLAnimationTypeThrowLine)];
    [self.datas addObject:ZLTableItem.tableItem(@"基础动画", @"AnimationViewController", ZLAnimationTypeBasic)];
    [self.datas addObject:ZLTableItem.tableItem(@"关键帧动画", @"AnimationViewController", ZLAnimationTypeKeyframe)];
    [self.datas addObject:ZLTableItem.tableItem(@"转场动画", @"AnimationViewController", ZLAnimationTypeTransition)];
    [self.datas addObject:ZLTableItem.tableItem(@"仿射变换", @"AnimationViewController", ZLAnimationTypeAffine)];
    
    [self.datas addObject:ZLTableItem.tableItem(@"翻页转场动画", @"ZLPageCurlController", ZLAnimationTypeUnknow)];
    
    
    [self.tableView reloadData];
}

#pragma mark - UITableViewDataSource

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return self.datas.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass(UITableViewCell.class) forIndexPath:indexPath];
    ZLTableItem *item = self.datas[indexPath.row];
    cell.textLabel.text = item.name;
    cell.detailTextLabel.text = item.vcName;
    return cell;
}

#pragma mark - UITableViewDelegate

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
    ZLTableItem *item = self.datas[indexPath.row];

    if (item.animationType == ZLAnimationTypeUnknow) {
        [self pushToVC:item.vcName withTitle:item.name];
    } else {
        [self pushToAnimationVCWithTitle:item.name type:item.animationType];
    }
}

#pragma mark - Private Method

- (void)pushToAnimationVCWithTitle:(NSString *)title type:(ZLAnimationType)type {
    AnimationViewController *vc = [[AnimationViewController alloc] init];
    vc.title = title;
    vc.animationType = type;
    [self.navigationController pushViewController:vc animated:true];
}

#pragma mark - Getter

- (NSMutableArray *)datas {
    if (!_datas) {
        _datas = [NSMutableArray new];
    }
    return _datas;
}

- (UITableView *)tableView {
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        [_tableView registerClass:UITableViewCell.class forCellReuseIdentifier:NSStringFromClass(UITableViewCell.class)];
    }
    return _tableView;
}

@end
